package com.swb.mybatis04emp.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @title: ${NAME}
 * @author: 流沐颖
 * @date:2022/6/2 8:31
 * @description:
 * @version: study
 */
@WebFilter("/*")
public class Filter01_Charset implements Filter {
    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        // 设置post请求的编码
        req.setCharacterEncoding("utf-8");
        // 设置响应后的编码
        resp.setContentType("text/html;charset=utf-8");
        chain.doFilter(req, resp);
    }

    @Override
    public void init(FilterConfig config) throws ServletException {

    }

}
